function embedProperties(){
    var json_spectrum_settings = {
        color: "#ECC",
        showInput: true,
        className: "full-spectrum",
        showInitial: true,
        showPalette: true,
        showSelectionPalette: true,
        maxPaletteSize: 10,
        preferredFormat: "hex",
        localStorageKey: "spectrum.demo",
        move: function (color) {
            
        },
        show: function () {
        
        },
        beforeShow: function () {
        
        },
        hide: function () {
        
        },
        change: function() {
            
        },
        palette: [
            ["rgb(0, 0, 0)", "rgb(67, 67, 67)", "rgb(102, 102, 102)",
            "rgb(204, 204, 204)", "rgb(217, 217, 217)","rgb(255, 255, 255)"],
            ["rgb(152, 0, 0)", "rgb(255, 0, 0)", "rgb(255, 153, 0)", "rgb(255, 255, 0)", "rgb(0, 255, 0)",
            "rgb(0, 255, 255)", "rgb(74, 134, 232)", "rgb(0, 0, 255)", "rgb(153, 0, 255)", "rgb(255, 0, 255)"], 
            ["rgb(230, 184, 175)", "rgb(244, 204, 204)", "rgb(252, 229, 205)", "rgb(255, 242, 204)", "rgb(217, 234, 211)", 
            "rgb(208, 224, 227)", "rgb(201, 218, 248)", "rgb(207, 226, 243)", "rgb(217, 210, 233)", "rgb(234, 209, 220)", 
            "rgb(221, 126, 107)", "rgb(234, 153, 153)", "rgb(249, 203, 156)", "rgb(255, 229, 153)", "rgb(182, 215, 168)", 
            "rgb(162, 196, 201)", "rgb(164, 194, 244)", "rgb(159, 197, 232)", "rgb(180, 167, 214)", "rgb(213, 166, 189)", 
            "rgb(204, 65, 37)", "rgb(224, 102, 102)", "rgb(246, 178, 107)", "rgb(255, 217, 102)", "rgb(147, 196, 125)", 
            "rgb(118, 165, 175)", "rgb(109, 158, 235)", "rgb(111, 168, 220)", "rgb(142, 124, 195)", "rgb(194, 123, 160)",
            "rgb(166, 28, 0)", "rgb(204, 0, 0)", "rgb(230, 145, 56)", "rgb(241, 194, 50)", "rgb(106, 168, 79)",
            "rgb(69, 129, 142)", "rgb(60, 120, 216)", "rgb(61, 133, 198)", "rgb(103, 78, 167)", "rgb(166, 77, 121)",
            "rgb(91, 15, 0)", "rgb(102, 0, 0)", "rgb(120, 63, 4)", "rgb(127, 96, 0)", "rgb(39, 78, 19)", 
            "rgb(12, 52, 61)", "rgb(28, 69, 135)", "rgb(7, 55, 99)", "rgb(32, 18, 77)", "rgb(76, 17, 48)"]
        ]
    }
    
    
    //WHEN CHECK ALLOW HIGHLIGHTS
    if($('[name="allow_highlights"]').length >= 1 ){
        var DOI = $("#popup_container").attr("data-object-id");
        var field_elem = $("#setObject_"+DOI).find(".getFields_"+DOI);//.attr("embed-hl-data")
        //RESTORE CHECKED ALLOW HIGHLIGHTS
        if(field_elem.attr("allow-highlights") == "true"){
            $('[name="allow_highlights"]').prop("checked",true);
        }else{
            $('[name="allow_highlights"]').prop("checked",false);
        }
        //SET ON CHANGE OF ALLOW HIGHLIGHTS
        $('[name="allow_highlights"]').on("change",function(ev){
            var DOI = $("#popup_container").attr("data-object-id");
            var field_elem = $("#setObject_"+DOI).find(".getFields_"+DOI);//.attr("embed-hl-data")
            field_elem.attr("allow-highlights",$(this).prop("checked"));
        })
    }
    //WHEN RADIO CHECK ALLOW HIGHLIGHT TYPE
    if($('[name="highlight_type"]').length >= 1 ){
        var DOI = $("#popup_container").attr("data-object-id");
        var field_elem = $("#setObject_"+DOI).find(".getFields_"+DOI);
        //RESTORE CHECKED ALLOW HIGHLIGHTS
        if(field_elem.attr("highlight-type") == "row"){
            $('[name="highlight_type"][value="row"]').prop("checked",true);
        }else{
            $('[name="highlight_type"][value="cell"]').prop("checked",true);
        }
        //SET ON CHANGE OF ALLOW HIGHLIGHTS
        $('[name="highlight_type"]').on("change",function(ev){
            var DOI = $("#popup_container").attr("data-object-id");
            var field_elem = $("#setObject_"+DOI).find(".getFields_"+DOI);
            field_elem.attr("highlight-type",$(this).val());
        })
    }
    //WHEN EXISTING HIGHLIGHTED CONTAINER
    if($(".highlight-row-prop").length >= 1){
        {//VERSION 1 HIGHLIGHT PROPERTY
            var containtment = $(".highlight-row-prop");
            containtment.find(".chooseColor").spectrum(json_spectrum_settings);
            
            //THIS IS FOR DYNAMIC HIGHLIGHTING
            containtment.find(".design-embed-highlights-prop").find("tr.HL_RULE_PROP1, tr.HL_RULE_PROP2").each(function(eqi){
                var dis_rowprop = $(this);
                var row_action = $(
                    '<div style="position: absolute;right: 5px; bottom: -16px;z-index:100;">'+
                        '<i class="addHLRule fa fa-plus icon-plus-sign cursor"></i>'+
                        '<i class="subtractHLRule fa fa-minus icon-minus-sign cursor" style="display:none; margin-left:5px;"></i>'+
                    '</div>'
                );
                if(dis_rowprop.hasClass("HL_RULE_PROP2")){
                    var select_relative_wrap = dis_rowprop.find(".relative-wrap");
                    select_relative_wrap.last().append(row_action);
                    var select_condition_type = select_relative_wrap.find(".choose-condition-type");
                    bindAddHLRULE(row_action);
                    bindSubtractHLRULE(row_action);
                    bindConditionTypeHLRULE(select_condition_type);
                }else if(dis_rowprop.hasClass("HL_RULE_PROP1")){
                    //nothing
                }
            })
            restoreSetValHLRULE();
        }
        // {//VERSION 2 HIGHLIGHT PROPERTY
        //     var containtment = $(".highlight-row-prop");
        //     var tbl_design_embed_highlights_prop = containtment.find('.design-embed-highlights-prop');
        //     containtment.find(".chooseColor").spectrum(json_spectrum_settings);
            
            
            
        //     var tee_arrs = containtment.find(".design-embed-highlights-prop").find("tr");
            
        //     tee_arrs.each(function(eqi){
        //         var row_action = $(
        //             '<div style="position: absolute;left: 0px;bottom: 0px;z-index:100;">'+
        //                 '<i class="addHLRule icon-plus-sign cursor"></i>'+
        //                 '<i class="subtractHLRule icon-minus-sign cursor" style="display:none;"></i>'+
        //             '</div>'
        //         );
        //         $(this).children("td").first().children(".relative-wrap").append(row_action);
        //         bindAddHLRULE(row_action);
        //     })

        // }
    }

    {//VERSION 1 HIGHLIGHT PROPERTY
        function restoreSetValHLRULE(){
            var containtment = $(".highlight-row-prop");
            //RESTORE SET VALUES
            var hlc_tbl = containtment.find(".design-embed-highlights-prop");
            var DOI = $("#popup_container").attr("data-object-id");
            var field_elem = $("#setObject_"+DOI).find(".getFields_"+DOI);//.attr("embed-hl-data")
            if(typeof field_elem.attr("embed-hl-data") != "undefined"){
                try{
                    var json_e_hl = JSON.parse(field_elem.attr("embed-hl-data"));
                    $.each(json_e_hl,function(eqi,value){
                        if(eqi != 0){
                            $(".HL_RULE_PROP2").eq(eqi-1).find('.addHLRule').click();
                        }
                        if(hlc_tbl.length >= 1 ){
                            // value['hl_color']
                            // value['hl_fn']
                            // value['condition_type']
                            // value['hl_value']
                            // value['hl_value2']
                            $(".HL_RULE_PROP1").eq(eqi).find('.chooseColor.hl-color').spectrum("set", value['hl_color']);
                            $(".HL_RULE_PROP1").eq(eqi).find('.fieldname-basis-highlight.hl-fn').val(value['hl_fn']);
                            $(".HL_RULE_PROP2").eq(eqi).find('.choose-condition-type').val(value['condition_type']);
                            $(".HL_RULE_PROP2").eq(eqi).find('.hl-value').val(value['hl_value']);
                            $(".HL_RULE_PROP2").eq(eqi).find('.hl-value2').val(value['hl_value2']);
                            $(".HL_RULE_PROP2").eq(eqi).find('.value-type-HL[value="'+value['value_type']+'"]').prop("checked",true);
                            if(value['condition_type'] == "range" || value['condition_type'] == "in_between"){
                                $(".HL_RULE_PROP2").eq(eqi).find('.hl-value2').css("display","inline-block");
                            }
                            // var hlc_tr = hlc_tbl.find("tr").eq(eqi)
                            // hlc_tr.find(".chooseColor").spectrum("set",value["hl_color"]);
                            // //.css("background-color", value["hl_color"]);
                            // // hlc_tr.find(".hl-fn").val(value["hl_fn"]); // or this below
                            // //         hlc_tr.find(".hl-fn option[value='"+value["hl_fn"]+"']").prop("selected",true);
                            // hlc_tr.find(".hl-value").val(value["hl_value"])
                        }
                    })
                }catch(err){

                }
            }
        }
        function bindAddHLRULE(dis_ele){
            var element_add = $(dis_ele);
            element_add.find(".addHLRule").on("click",function(){
                var dis_prop2 = $(this).parents('tr.HL_RULE_PROP2').eq(0);
                var dis_prop1 = dis_prop2.prev();
                var selected_to_clone = dis_prop1.add(dis_prop2).clone(true);
                var tbody_row_container = $(this).parents("tbody").eq(0);
                var new_index_row = tbody_row_container.children("tr").last().index()+1;
                // console.log($('.highlight-row-prop').data('countAdds'))
                if(typeof $('.highlight-row-prop').data('countAdds') === "undefined"){
                    $('.highlight-row-prop').data('countAdds', 1)
                }
                var countAdds = $('.highlight-row-prop').data('countAdds');
               /* alert(countAdds)*/
                //modify display here
                selected_to_clone.find(".value-type-HL").each(function(eqi){
                    $(this).attr("name",$(this).attr("data-name")+"_r"+countAdds);
                    
                    if($(this).attr('value') == 'static'){
                         $(this).attr("id","DHLradioStatic_r"+countAdds);
                         $(this).next().attr('for', 'DHLradioStatic_r'+countAdds)
                    }else {
                        $(this).attr("id","DHLradioComputed_r"+countAdds);
                        $(this).next().attr('for', 'DHLradioComputed_r'+countAdds)
                    }
                   
                    if($(this).val() == "static"){
                        // alert(23)
                        $(this).prop("checked",true);
                    }
                });
                dis_prop2.after(selected_to_clone);
                // tbody_row_container.append(selected_to_clone);
                selected_to_clone.find(".sp-replacer.sp-light.full-spectrum").remove();
                var location_for_color_picking = $(selected_to_clone.find(".chooseColor.hl-color").parent());
                selected_to_clone.find(".chooseColor.hl-color").remove();
                var color_picking = $('<input type="text" class="chooseColor hl-color" data-properties-type="embRowColor" data-type="emb-highlight-color">');
                location_for_color_picking.append(color_picking);
                color_picking.spectrum(json_spectrum_settings);
                selected_to_clone.find(".subtractHLRule").css("display","inline-block");

                $('.highlight-row-prop').data('countAdds',$('.highlight-row-prop').data('countAdds')+1)
            })
        }
        function bindSubtractHLRULE(dis_ele){
            var element_subtract = $(dis_ele);
            element_subtract.find(".subtractHLRule").on("click",function(){
                var dis_prop2 = $($(this).parents('tr.HL_RULE_PROP2').eq(0));
                var dis_prop1 = $(dis_prop2.prev());
                dis_prop1.remove();
                dis_prop2.remove();
            })
        }
        function bindConditionTypeHLRULE(dis_ele){
            var element_CT = $(dis_ele);
            element_CT.on("change",function(){
                var value_nito = $(this).val();
                var location_value_container = $(this).parent();
                if(value_nito == "range" || value_nito == "in_between"){
                    location_value_container.find(".hl-value2").css("display","inline-block");
                    location_value_container.find(".hl-value").css("width","49%");
                }else{
                    location_value_container.find(".hl-value2").css("display","none");
                    location_value_container.find(".hl-value").css("width","");
                }
            });
        }
    }
    // {//VERSION 2 HIGHLIGHT PROPERTY
    //     function restoreSetValHLRULE(){
    //         var containtment = $(".highlight-row-prop");
    //         //RESTORE SET VALUES
    //         var hlc_tbl = containtment.find(".design-embed-highlights-prop");
    //         var DOI = $("#popup_container").attr("data-object-id");
    //         var field_elem = $("#setObject_"+DOI).find(".getFields_"+DOI);//.attr("embed-hl-data")
    //         if(typeof field_elem.attr("embed-hl-data") != "undefined"){
    //             try{
    //                 var json_e_hl = JSON.parse(field_elem.attr("embed-hl-data"));
    //                 $.each(json_e_hl,function(eqi,value){
    //                     if(eqi != 0){
    //                         $(".HL_RULE_PROP2").eq(eqi-1).find('.addHLRule').click();
    //                     }
    //                     if(hlc_tbl.length >= 1 ){
    //                         // value['hl_color']
    //                         // value['hl_fn']
    //                         // value['condition_type']
    //                         // value['hl_value']
    //                         // value['hl_value2']
    //                         $(".HL_RULE_PROP1").eq(eqi).find('.chooseColor.hl-color').spectrum("set", value['hl_color']);
    //                         $(".HL_RULE_PROP1").eq(eqi).find('.fieldname-basis-highlight.hl-fn').val(value['hl_fn']);
    //                         $(".HL_RULE_PROP2").eq(eqi).find('.choose-condition-type').val(value['condition_type']);
    //                         $(".HL_RULE_PROP2").eq(eqi).find('.hl-value').val(value['hl_value']);
    //                         $(".HL_RULE_PROP2").eq(eqi).find('.hl-value2').val(value['hl_value2']);
    //                         // var hlc_tr = hlc_tbl.find("tr").eq(eqi)
    //                         // hlc_tr.find(".chooseColor").spectrum("set",value["hl_color"]);
    //                         // //.css("background-color", value["hl_color"]);
    //                         // // hlc_tr.find(".hl-fn").val(value["hl_fn"]); // or this below
    //                         // //         hlc_tr.find(".hl-fn option[value='"+value["hl_fn"]+"']").prop("selected",true);
    //                         // hlc_tr.find(".hl-value").val(value["hl_value"])
    //                     }
    //                 })
    //             }catch(err){

    //             }
    //         }
    //     }
    //     function bindAddHLRULE(dis_ele){
    //         var element_add = $(dis_ele);
    //         element_add.find(".addHLRule").on("click",{"element_add":element_add},function(e){
    //             alert(123)
    //             var passed_data = e.data;
    //             var dis_tee_arr_prop = $(this).parents("tr").eq(0);
    //             var selected_clone = dis_tee_arr_prop.clone(true);
    //             var tbody_row_container = $(this).parents("tbody").eq(0);
    //             tbody_row_container.append(selected_clone);
    //             selected_clone.find(".sp-replacer.sp-light.full-spectrum").remove();
    //             var location_for_color_picking = $(selected_clone.find(".chooseColor.hl-color").parent());
    //             selected_clone.find(".chooseColor.hl-color").remove();
    //             var color_picking = $('<input type="text" class="chooseColor hl-color" data-properties-type="embRowColor" data-type="emb-highlight-color">');
    //             location_for_color_picking.append(color_picking);
    //             color_picking.spectrum(json_spectrum_settings);
    //             selected_to_clone.find(".subtractHLRule").css("display","inline-block");



    //             // var dis_prop2 = $(this).parents('tr').eq(0);
    //             // var dis_prop1 = dis_prop2.prev();
    //             // var selected_to_clone = dis_prop1.add(dis_prop2).clone(true);
    //             // var tbody_row_container = $(this).parents("tbody").eq(0);


    //             // tbody_row_container.append(selected_to_clone);
    //             // selected_to_clone.find(".sp-replacer.sp-light.full-spectrum").remove();
    //             // var location_for_color_picking = $(selected_to_clone.find(".chooseColor.hl-color").parent());
    //             // selected_to_clone.find(".chooseColor.hl-color").remove();
    //             // var color_picking = $('<input type="text" class="chooseColor hl-color" data-properties-type="embRowColor" data-type="emb-highlight-color">');
    //             // location_for_color_picking.append(color_picking);
    //             // color_picking.spectrum(json_spectrum_settings);
    //             // selected_to_clone.find(".subtractHLRule").css("display","inline-block");
    //         })
    //     }
    //     function bindSubtractHLRULE(dis_ele){
    //         var element_subtract = $(dis_ele);
    //         element_subtract.find(".subtractHLRule").on("click",function(){
    //             var dis_prop2 = $($(this).parents('tr.HL_RULE_PROP2').eq(0));
    //             var dis_prop1 = $(dis_prop2.prev());
    //             dis_prop1.remove();
    //             dis_prop2.remove();
    //         })
    //     }
    //     function bindConditionTypeHLRULE(dis_ele){
    //         var element_CT = $(dis_ele);
    //         element_CT.on("change",function(){
    //             var value_nito = $(this).val();
    //             var location_value_container = $(this).parent();
    //             if(value_nito == "range" || value_nito == "in_between"){
    //                 location_value_container.find(".hl-value2").css("display","inline-block");
    //                 location_value_container.find(".hl-value").css("width","49%");
    //             }else{
    //                 location_value_container.find(".hl-value2").css("display","none");
    //                 location_value_container.find(".hl-value").css("width","");
    //             }
    //         });
    //     }
    // }

    //WHEN EMBED PROPERTY IS EXISTING
    if ($(".embedProperty").length >= 2) {
        var prop_choice_embed_ele = $('[name="embed_rfc_choice"]');
        if(prop_choice_embed_ele.length >= 1){
            prop_choice_embed_ele.on("change",function(e){
                var DOI = $("#popup_container").attr("data-object-id");
                var value_embed = $(this).val();
                if(value_embed == "static"){
                    $(".embed-result-field-computed-c").css("display","none");
                    $(".embed-result-field-c").css("display","");
                }else if(value_embed == "computed"){
                    $(".embed-result-field-c").css("display","none");
                    $(".embed-result-field-computed-c").css("display","");
                }
                $("#setObject_" + DOI).find(".getFields_"+ DOI).attr('rfc-choice',value_embed);
            });
        }
        var DOI = $("#popup_container").attr("data-object-id");

        if($("#setObject_" + DOI).find(".getFields_"+ DOI).attr('rfc-choice') ){
            // alert($("#setObject_" + DOI).find(".getFields_"+ DOI).attr('sc-choice') );
            var embed_choice_value = $("#setObject_" + DOI).find(".getFields_"+ DOI).attr('rfc-choice');
            if(embed_choice_value == "computed"){
                // $("[value='computed']",prop_choice_embed_ele).prop("checked",true);
                $('[value="computed"]'+prop_choice_embed_ele.selector).click();
                $(".embed-result-field-c").css("display","none");
            }else{
                // $("[value='static']",prop_choice_embed_ele).prop("checked",true);
                $('[value="static"]'+prop_choice_embed_ele.selector).click();
                $(".embed-result-field-computed-c").css("display","none");
            }
        }
        if($(".embed-result-field-formula").length >= 1 ){
            $(".embed-result-field-formula").on("keyup",function(){
                var DOI = $("#popup_container").attr("data-object-id");
                $("#setObject_" + DOI).find(".getFields_"+ DOI).attr('embed-computed-formula',$(this).val());
            });
            if($("#setObject_" + DOI).find(".getFields_"+ DOI).attr('embed-computed-formula') ){
                $(".embed-result-field-formula").val(
                    $("#setObject_" + DOI).find(".getFields_"+ DOI).attr('embed-computed-formula')
                );
            }
        }

        var embed_source_form_ele_container = $(".embedProperty").find(".embed_source_form");
        var loading_content = $('<div class="getFromsLoader form-select" style="display:inline-block;position:relative;vertical-align:middle;text-align:center;"><label style="color:black;position:reltive;font-size: 15px;display:inline-block;">Loading...</label><img src="/images/loader/loader.gif" class="display processorLoad" style="display: inline-block;"/></div>');

        //EMBED GET FORM LIST
        embed_source_form_ele_container.children(".embed-source-form").hide();
        embed_source_form_ele_container.prepend(loading_content);
        var embed_source_lookup_field_ele_container = $(".embedProperty").find(".embed_source_lookup_field");
        if (embed_source_lookup_field_ele_container.find(".getFromsLoader").length == 0) {
            var loading_content_active_fields = $('<div class="getFromsLoader form-select" style="display:inline-block;position:relative;vertical-align:middle;text-align:center;"><label style="color:black;position:reltive;font-size: 15px;display:inline-block;">Loading...</label><img src="/images/loader/loader.gif" class="display processorLoad" style="display: inline-block;"/></div>');
            embed_source_lookup_field_ele_container.find(".embed-source-lookup-field").hide();
            embed_source_lookup_field_ele_container.after(loading_content_active_fields);
        }
        $.post("/ajax/formbuilder", {action: "getFormList"}, function(dataEchoResults) {
            var json_p = JSON.parse(dataEchoResults);
            var embed_source_form_ele_container = $(".embedProperty").find(".embed_source_form");
            //GET LIST OF FORMS
            var collect_append_option = '<option>--Select--</option>';
            for (var c in json_p) {
                console.log(json_p[c])
                collect_append_option
                        += '<option frm-id="' + json_p[c]["wsID"] + '" active-fields="' + json_p[c]["active_fields"] + '" value="' + json_p[c]["wsID"] + '" >' + json_p[c]["form_name"] + '</option>';
            }

            loading_content.fadeOut(function() {
                var embed_source_form_ele_container = $(".embedProperty").find(".embed_source_form");

                embed_source_form_ele_container.children(".embed-source-form").html(collect_append_option);
                embed_source_form_ele_container.children(".embed-source-form").show();
                loading_content_active_fields.fadeOut(function() {
                    embed_source_lookup_field_ele_container.find(".embed-source-lookup-field").show();
                    $(this).remove();
                });

                //RESTORE SAVED VALUES
                var field_id_on_form = $("#popup_container").attr("data-object-id");
                if (typeof $(".getFields_" + field_id_on_form).attr("embed-source-form-val-id") != "undefined") {
                    embed_source_form_ele_container.children(".embed-source-form").children("option[frm-id='" + $(".getFields_" + field_id_on_form).attr("embed-source-form-val-id") + "']").prop("selected", true);
                }

                //GET FORM ACTIVE FIELD LIST BASED ON SELECTED SOURCE LIST OF FORMS
                var collect_append_option_active_field = "<option>--Select--</option><option value='TrackNo' >TrackNo</option>";
                if (embed_source_form_ele_container.children(".embed-source-form").children("option:selected").length >= 1) {
                    var active_fields = embed_source_form_ele_container.children(".embed-source-form").children("option:selected").attr("active-fields");
                    if (typeof active_fields != "undefined") {
                        if (active_fields.length >= 1) {
                            active_fields = active_fields.split(",");
                            for (var ctr = 0; ctr < active_fields.length; ctr++) {
                                collect_append_option_active_field += '<option value="' + active_fields[ctr] + '">' + active_fields[ctr] + '</option>';
                            }
                        }
                    }
                }
                var appended_options_active_field = $(collect_append_option_active_field);
                embed_source_lookup_field_ele_container.find(".embed-source-lookup-field").html(appended_options_active_field);
                //RESTORING VALUE OF SELECTED ACTIVE FIELD OF SOURCE FORM
                var getFieldSourceFormID_val = $(".getFields_" + field_id_on_form).attr("embed-source-form-val-id");
                var getFieldSourceFormLookupField_val = $(".getFields_" + field_id_on_form).attr("embed-source-lookup-active-field-val");
                if (typeof getFieldSourceFormLookupField_val != "undefined") {
                    if (
                            getFieldSourceFormID_val == embed_source_form_ele_container.children(".embed-source-form").children("option:selected").val() &&
                            appended_options_active_field.parent().children("option[value='" + getFieldSourceFormLookupField_val + "']").length >= 1
                            ) {
                        appended_options_active_field.parent().children("option[value='" + getFieldSourceFormLookupField_val + "']").prop("selected", true);

                    }
                }

                


                //SET ONCHANGE EVENT EMBED SOURCE FORMS
                embed_source_form_ele_container.children(".embed-source-form").on({
                    "change": function() {
                        var embed_source_form_ele_container = $(".embedProperty").find(".embed_source_form");

                        var field_id_on_form = $("#popup_container").attr("data-object-id");
                        $(".getFields_" + field_id_on_form).attr("embed-source-form-val-id", $(this).val());

                        //GET ACTIVE FIELDS OF SOURCE FORM
                        var collect_append_option_active_field = "<option>--Select--</option>";
                        if($(this).val() != "--Select--"){
                            collect_append_option_active_field += "<option value='TrackNo' >TrackNo</option>";
                        }
                        if (embed_source_form_ele_container.children(".embed-source-form").children("option:selected").length >= 1) {
                            var active_fields = embed_source_form_ele_container.children(".embed-source-form").children("option:selected").attr("active-fields");
                            if (typeof active_fields != "undefined") {
                                if (active_fields.length >= 1) {
                                    active_fields = active_fields.split(",");
                                    for (var ctr = 0; ctr < active_fields.length; ctr++) {
                                        collect_append_option_active_field += '<option value="' + active_fields[ctr] + '">' + active_fields[ctr] + '</option>';
                                    }
                                }
                            }
                        }
                        var appended_options_active_field = $(collect_append_option_active_field);
                        embed_source_lookup_field_ele_container.find(".embed-source-lookup-field").html(appended_options_active_field);

                        //RESTORING VALUE OF SELECTED ACTIVE FIELD OF SOURCE FORM
                        var getFieldSourceFormID_val = $(".getFields_" + field_id_on_form).attr("embed-source-form-val-id");
                        var getFieldSourceFormLookupField_val = $(".getFields_" + field_id_on_form).attr("embed-source-lookup-active-field-val");
                        if (typeof getFieldSourceFormLookupField_val != "undefined") {
                            if (
                                    getFieldSourceFormID_val == $(this).val() &&
                                    appended_options_active_field.parent().children("option[value='" + getFieldSourceFormLookupField_val + "']").length >= 1
                                    ) {
                                // alert("HALA")
                                // console.log(appended_options_active_field)
                                // console.log("kulangot")
                                // console.log(getFieldSourceFormLookupField_val)
                                // console.log($(appended_options_active_field,"[value='"+getFieldSourceFormLookupField_val+"']"))
                                appended_options_active_field.parent().children("option[value='" + getFieldSourceFormLookupField_val + "']").prop("selected", true);
                            }
                        }
                        // if($(".highlight-row-prop").length >= 1){
                        //     var highlight_containtment = $(".highlight-row-prop");
                        //     highlight_containtment.find(".fieldname-basis-highlight").html(collect_append_option_active_field)
                        // }
                        //RESTORE SELECTED DISPLAY COLUMN WHEN THE FORM IS CHANGED
                        if($('.embed-display-column').length >= 1){
                            var display_col_containtment = $(".embed-display-column");
                            display_col_containtment.html(collect_append_option_active_field)
                            display_col_containtment.children('option:contains("--Select--")').remove();
                            //RESTORE VALUE OF CHOSEN COLUMN
                            if($(".getFields_" + field_id_on_form+"[embed-column-data]").length >= 1){
                                var embed_col_choose_data = $(".getFields_" + field_id_on_form+"[embed-column-data]").attr('embed-column-data');
                                var embed_col_choose_data_json = JSON.parse(embed_col_choose_data);
                                for (var ii in embed_col_choose_data_json) {
                                    display_col_containtment.children('option:contains('+embed_col_choose_data_json[ii]+')').prop("selected",true);
                                };
                            }
                        }
                        //RESTORE HIGHLIGHT FIELDNAME VALUE
                        if($(".highlight-row-prop").length >= 1){ //onchange ng form pili
                            var highlight_containtment = $(".highlight-row-prop");
                            var hlc_tbl = highlight_containtment.find(".design-embed-highlights-prop");
                            highlight_containtment.find(".fieldname-basis-highlight").html(collect_append_option_active_field)
                            if(hlc_tbl.length >= 1 ){
                                try{
                                    var json_e_hl = JSON.parse(field_elem.attr("embed-hl-data"));
                                    
                                    $.each(json_e_hl,function(eqi,value){
                                        // value['hl_fn'];
                                        if($('.HL_RULE_PROP1').eq(eqi).length >= 1){
                                            if($('.HL_RULE_PROP1').eq(eqi).find('.hl-fn').find('option[value="'+value['hl_fn']+'"]').length >= 1 ){
                                                $('.HL_RULE_PROP1').eq(eqi).find('.hl-fn').val(value['hl_fn']);
                                            }
                                        }
                                    })
                                }catch(err){

                                }
                            }
                            
                        }
                    }
                })
                embed_source_form_ele_container.children(".embed-source-form").change();
                //RESTORE HIGHLIGHT FIELDNAME VALUE
                if($(".highlight-row-prop").length >= 1){ //onchange ng form pili
                    var highlight_containtment = $(".highlight-row-prop");
                    var hlc_tbl = highlight_containtment.find(".design-embed-highlights-prop");
                    highlight_containtment.find(".fieldname-basis-highlight").html(collect_append_option_active_field)
                    if(hlc_tbl.length >= 1 ){
                        try{
                            var json_e_hl = JSON.parse(field_elem.attr("embed-hl-data"));
                            
                            $.each(json_e_hl,function(eqi,value){
                                // value['hl_fn'];
                                if($('.HL_RULE_PROP1').eq(eqi).length >= 1){
                                    $('.HL_RULE_PROP1').eq(eqi).find('.hl-fn').val(value['hl_fn']);
                                }
                            })
                        }catch(err){

                        }
                    }
                    
                }
                //appended_options_active_field
                $(this).remove();
            });
        });



        //EMBED GET FORM SOURCE LOOKUP ACTIVE FIELDS 
        var embed_source_lookup_field_ele_container = $(".embedProperty").find(".embed_source_lookup_field");
        embed_source_lookup_field_ele_container.find(".embed-source-lookup-field").html('<option>--Select--</option>');

        //SET ON CHANGE OF embed source lookup active field
        embed_source_lookup_field_ele_container.find(".embed-source-lookup-field").on({
            "change": function() {
                $(".getFields_" + field_id_on_form).attr("embed-source-lookup-active-field-val", $(this).val());
            }
        });



 
        //EMBED GET LIST OF FIELD NAMES
        var embed_result_field_ele_container = $(".embedProperty").find(".embed_result_field");
        //COLLECT FIELD NAMES
        // alert("TESTING")

        var field_names = '<option>--Select--</option>';
        $(".workspace.formbuilder_ws").find(".setObject").each(function() {
            // console.log("WHOA")
            // console.log($(this).find(".getFields").eq(0))
            if (
                    $(this).find(".form-table").length >= 1 ||
                    $(this).find(".form-tabbable-pane").length >= 1 ||
                    $(this).find('[data-type="createLine"]').length >= 1 ||
                    $(this).attr("data-type") == "labelOnly" ||
                    $(this).attr("data-type") == "embeded-view" ||
                    $(this).attr("data-type") == "imageOnly"
                ) {
                return true;
            }
            var obj_id = $(this).attr("data-object-id");
            var obj_fields = $(this).find(".getFields_" + obj_id).eq(0);
            if (typeof obj_fields == "undefined") {

            } else {
                field_names
                        += '<option obj-id="' + obj_id + '" value="' + obj_fields.attr("name") + '">' + obj_fields.attr("name") + '</option>';
            }
        });
        embed_result_field_ele_container.find(".embed-result-field").html(field_names);

        //RESTORE SAVED VALUES
        var field_id_on_form = $("#popup_container").attr("data-object-id");
        if (typeof $(".getFields_" + field_id_on_form).attr("erf-obj-id-val") != "undefined") {
            embed_result_field_ele_container.find(".embed-result-field").find("option[obj-id='" + $(".getFields_" + field_id_on_form).attr("erf-obj-id-val") + "']").prop("selected", true);
        }

        //SET ONCHANGE EVENT
        // console.log(embed_result_field_ele_container)
        embed_result_field_ele_container.find(".embed-result-field").on({
            "change": function() {
                var selected_obj_id = $(this).children("option:selected").attr("obj-id");
                var field_id_on_form = $("#popup_container").attr("data-object-id");
                $(".getFields_" + field_id_on_form).attr("embed-result-field-val", $(this).val());
                $(".getFields_" + field_id_on_form).attr("erf-obj-id-val", selected_obj_id);
            }
        });
    }
}